using System;
using System.Collections;
using Microsoft.Xna.Framework;
using Imagination;

namespace Imagination.Collisions
{
    /// <summary>
    /// SimpleDetector is a basic implementation of a collision detector.
    /// It detects collisions with bounding spheres only.
    /// </summary>
	public class SimpleDetector : CollisionDetector
	{
		public override Collision DetectCollision(Thing thing1, Thing thing2)
		{
			System.Diagnostics.Debug.Assert(thing1 != thing2);
			Collision collision = null;

			if ((thing1.Model != null) && (thing2.Model != null))
			{
				Vector3 separation = thing1.Position - thing2.Position;

                float radiiSum = thing1.Boundary.Radius + thing2.Boundary.Radius;
				float distance = separation.Length();
				if (distance <= radiiSum)
				{
					counterHits++;
                    collision = new Collision(thing1, thing2);
				}
				else
				{
					counterMisses++;
				}
			}
			
			return collision;
		}

        public override string ToString()
        {
            return String.Format("SimpleDetector: {0} hits/{1} misses", counterHits, counterMisses);
        }
	}
}
